var requestHandlers = require('./requestHandlers.js');
function route (pathname,handle,res,postData) {
/*	var pageContent;
	if (pathname == '/') {
		pageContent = 'This is index page';
	}else if (pathname == '/start') {
		pageContent = 'This is start page';
	}else{
		pageContent = 'I can\'t find this page';
	}
	return pageContent;
*/
//	去除这种判断，我们添加真正的处理函数-requestHandlers


/*	var requestHandle = new requestHandlers();
	if (pathname == '/') {
		pageContent = requestHandle.index();
	}else if (pathname == '/start') {
		pageContent = requestHandle.start();
	}else{
		pageContent = 'I can\'t find this page';
	}
	return pageContent;*/
//	如果像上面那么处理，那么requestHandlers模块就完全没有意义

	if (typeof handle[pathname] === 'function') {
		return handle[pathname](res,postData);
	}else{
		res.writeHead(404 , {"Content-Type":"text/html"});
		res.write("<h1>NOT FOUND</h1>");
		res.end();
	}

}

exports.route = route;